package com.dd.common.dto.user;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * @author cheng
 */
@Data
@Schema(description = "用户登录DTO")
public class UserLoginDTO implements Serializable {
// 不用单独设置登录方式，username email phone 允许为 null，谁不是null，就作为登录方式，也就是前端一个输入框支持三种登录方式
//    @NotBlank(message = "登录方式不能为空")
//    @Pattern(regexp = "username|email|phone", message = "登录方式必须是 username、email 或 phone")
//    @Schema(description = "登录方式: username/email/phone", example = "username", requiredMode = Schema.RequiredMode.REQUIRED)
//    private String loginType;

    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 32, message = "密码长度必须在6到32位之间")
    @Pattern(regexp = "^[a-zA-Z0-9_]{6,32}$", message = "密码只能包含字母、数字、下划线，长度6-32个字符")
    @Schema(description = "密码（前端明文传输，后端存储哈希值）", example = "123456", requiredMode = Schema.RequiredMode.REQUIRED)
    private String password;

    // 在 Swagger3 中，字段没有 requiredMode 显示声明必传，默认标识为可选
    @Schema(description = "账号用户名（仅限字母、数字、下划线）", example = "admin_user_1")
    @Pattern(regexp = "^[a-zA-Z0-9_]{4,30}$", message = "用户名必须由4-30位字母、数字或下划线组成")
    private String username;

    @Email(message = "邮箱格式不正确")
    @Schema(description = "邮箱地址", example = "user@example.com")
    private String email;

    @Pattern(regexp = "^\\+?[0-9]{10,15}$", message = "手机号格式不正确，支持国际格式")
    @Schema(description = "手机号码（可选，支持国际号码）", example = "+8613812345678")
    private String phone;
}
